7e9e9423ec2d5e66c70426c44d69dcf2cbf720f9
[openwrt/openwrt.git] /
1 From 564923b02c1d2fe02ee789f9849ff79979b63b9f Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Mon, 11 Aug 2025 17:31:37 +0200
4 Subject: [PATCH 1/6] net: airoha: npu: Add NPU wlan memory initialization
5 commands
6
7 Introduce wlan_init_reserved_memory callback used by MT76 driver during
8 NPU wlan offloading setup.
9 This is a preliminary patch to enable wlan flowtable offload for EN7581
10 SoC with MT76 driver.
11
12 Reviewed-by: Simon Horman <horms@kernel.org>
13 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
14 Link: https://patch.msgid.link/20250811-airoha-en7581-wlan-offlaod-v7-2-58823603bb4e@kernel.org
15 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
16 ---
17 drivers/net/ethernet/airoha/airoha_npu.c | 82 ++++++++++++++++++++++++
18 drivers/net/ethernet/airoha/airoha_npu.h | 38 +++++++++++
19 2 files changed, 120 insertions(+)
20
21 --- a/drivers/net/ethernet/airoha/airoha_npu.c
22 +++ b/drivers/net/ethernet/airoha/airoha_npu.c
23 @@ -124,6 +124,13 @@ struct ppe_mbox_data {
24 };
25 };
26
27 +struct wlan_mbox_data {
28 + u32 ifindex:4;
29 + u32 func_type:4;
30 + u32 func_id;
31 + DECLARE_FLEX_ARRAY(u8, d);
32 +};
33 +
34 static int airoha_npu_send_msg(struct airoha_npu *npu, int func_id,
35 void *p, int size)
36 {
37 @@ -390,6 +397,80 @@ out:
38 return err;
39 }
40
41 +static int airoha_npu_wlan_msg_send(struct airoha_npu *npu, int ifindex,
42 + enum airoha_npu_wlan_set_cmd func_id,
43 + void *data, int data_len, gfp_t gfp)
44 +{
45 + struct wlan_mbox_data *wlan_data;
46 + int err, len;
47 +
48 + len = sizeof(*wlan_data) + data_len;
49 + wlan_data = kzalloc(len, gfp);
50 + if (!wlan_data)
51 + return -ENOMEM;
52 +
53 + wlan_data->ifindex = ifindex;
54 + wlan_data->func_type = NPU_OP_SET;
55 + wlan_data->func_id = func_id;
56 + memcpy(wlan_data->d, data, data_len);
57 +
58 + err = airoha_npu_send_msg(npu, NPU_FUNC_WIFI, wlan_data, len);
59 + kfree(wlan_data);
60 +
61 + return err;
62 +}
63 +
64 +static int
65 +airoha_npu_wlan_set_reserved_memory(struct airoha_npu *npu,
66 + int ifindex, const char *name,
67 + enum airoha_npu_wlan_set_cmd func_id)
68 +{
69 + struct device *dev = npu->dev;
70 + struct resource res;
71 + int err;
72 + u32 val;
73 +
74 + err = of_reserved_mem_region_to_resource_byname(dev->of_node, name,
75 + &res);
76 + if (err)
77 + return err;
78 +
79 + val = res.start;
80 + return airoha_npu_wlan_msg_send(npu, ifindex, func_id, &val,
81 + sizeof(val), GFP_KERNEL);
82 +}
83 +
84 +static int airoha_npu_wlan_init_memory(struct airoha_npu *npu)
85 +{
86 + enum airoha_npu_wlan_set_cmd cmd = WLAN_FUNC_SET_WAIT_NPU_BAND0_ONCPU;
87 + u32 val = 0;
88 + int err;
89 +
90 + err = airoha_npu_wlan_msg_send(npu, 1, cmd, &val, sizeof(val),
91 + GFP_KERNEL);
92 + if (err)
93 + return err;
94 +
95 + cmd = WLAN_FUNC_SET_WAIT_TX_BUF_CHECK_ADDR;
96 + err = airoha_npu_wlan_set_reserved_memory(npu, 0, "tx-bufid", cmd);
97 + if (err)
98 + return err;
99 +
100 + cmd = WLAN_FUNC_SET_WAIT_PKT_BUF_ADDR;
101 + err = airoha_npu_wlan_set_reserved_memory(npu, 0, "pkt", cmd);
102 + if (err)
103 + return err;
104 +
105 + cmd = WLAN_FUNC_SET_WAIT_TX_PKT_BUF_ADDR;
106 + err = airoha_npu_wlan_set_reserved_memory(npu, 0, "tx-pkt", cmd);
107 + if (err)
108 + return err;
109 +
110 + cmd = WLAN_FUNC_SET_WAIT_IS_FORCE_TO_CPU;
111 + return airoha_npu_wlan_msg_send(npu, 0, cmd, &val, sizeof(val),
112 + GFP_KERNEL);
113 +}
114 +
115 struct airoha_npu *airoha_npu_get(struct device *dev, dma_addr_t *stats_addr)
116 {
117 struct platform_device *pdev;
118 @@ -493,6 +574,7 @@ static int airoha_npu_probe(struct platf
119 npu->ops.ppe_deinit = airoha_npu_ppe_deinit;
120 npu->ops.ppe_flush_sram_entries = airoha_npu_ppe_flush_sram_entries;
121 npu->ops.ppe_foe_commit_entry = airoha_npu_foe_commit_entry;
122 + npu->ops.wlan_init_reserved_memory = airoha_npu_wlan_init_memory;
123
124 npu->regmap = devm_regmap_init_mmio(dev, base, &regmap_config);
125 if (IS_ERR(npu->regmap))
126 --- a/drivers/net/ethernet/airoha/airoha_npu.h
127 +++ b/drivers/net/ethernet/airoha/airoha_npu.h
128 @@ -6,6 +6,43 @@
129
130 #define NPU_NUM_CORES 8
131
132 +enum airoha_npu_wlan_set_cmd {
133 + WLAN_FUNC_SET_WAIT_PCIE_ADDR,
134 + WLAN_FUNC_SET_WAIT_DESC,
135 + WLAN_FUNC_SET_WAIT_NPU_INIT_DONE,
136 + WLAN_FUNC_SET_WAIT_TRAN_TO_CPU,
137 + WLAN_FUNC_SET_WAIT_BA_WIN_SIZE,
138 + WLAN_FUNC_SET_WAIT_DRIVER_MODEL,
139 + WLAN_FUNC_SET_WAIT_DEL_STA,
140 + WLAN_FUNC_SET_WAIT_DRAM_BA_NODE_ADDR,
141 + WLAN_FUNC_SET_WAIT_PKT_BUF_ADDR,
142 + WLAN_FUNC_SET_WAIT_IS_TEST_NOBA,
143 + WLAN_FUNC_SET_WAIT_FLUSHONE_TIMEOUT,
144 + WLAN_FUNC_SET_WAIT_FLUSHALL_TIMEOUT,
145 + WLAN_FUNC_SET_WAIT_IS_FORCE_TO_CPU,
146 + WLAN_FUNC_SET_WAIT_PCIE_STATE,
147 + WLAN_FUNC_SET_WAIT_PCIE_PORT_TYPE,
148 + WLAN_FUNC_SET_WAIT_ERROR_RETRY_TIMES,
149 + WLAN_FUNC_SET_WAIT_BAR_INFO,
150 + WLAN_FUNC_SET_WAIT_FAST_FLAG,
151 + WLAN_FUNC_SET_WAIT_NPU_BAND0_ONCPU,
152 + WLAN_FUNC_SET_WAIT_TX_RING_PCIE_ADDR,
153 + WLAN_FUNC_SET_WAIT_TX_DESC_HW_BASE,
154 + WLAN_FUNC_SET_WAIT_TX_BUF_SPACE_HW_BASE,
155 + WLAN_FUNC_SET_WAIT_RX_RING_FOR_TXDONE_HW_BASE,
156 + WLAN_FUNC_SET_WAIT_TX_PKT_BUF_ADDR,
157 + WLAN_FUNC_SET_WAIT_INODE_TXRX_REG_ADDR,
158 + WLAN_FUNC_SET_WAIT_INODE_DEBUG_FLAG,
159 + WLAN_FUNC_SET_WAIT_INODE_HW_CFG_INFO,
160 + WLAN_FUNC_SET_WAIT_INODE_STOP_ACTION,
161 + WLAN_FUNC_SET_WAIT_INODE_PCIE_SWAP,
162 + WLAN_FUNC_SET_WAIT_RATELIMIT_CTRL,
163 + WLAN_FUNC_SET_WAIT_HWNAT_INIT,
164 + WLAN_FUNC_SET_WAIT_ARHT_CHIP_INFO,
165 + WLAN_FUNC_SET_WAIT_TX_BUF_CHECK_ADDR,
166 + WLAN_FUNC_SET_WAIT_TOKEN_ID_SIZE,
167 +};
168 +
169 struct airoha_npu {
170 struct device *dev;
171 struct regmap *regmap;
172 @@ -29,6 +66,7 @@ struct airoha_npu {
173 dma_addr_t foe_addr,
174 u32 entry_size, u32 hash,
175 bool ppe2);
176 + int (*wlan_init_reserved_memory)(struct airoha_npu *npu);
177 } ops;
178 };
179